﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SWENAssignment.Sophia
{
    public partial class editCustomersDetails : System.Web.UI.Page
    {
        string c2;
        protected void Page_Load(object sender, EventArgs e)
        {
            
            c2 = Request.QueryString["roomNum"];

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string cd1_customerID = tbxCustomerID.Text;
            customersDetails cd1 = DBmanager.getByCustomerID(cd1_customerID);
            if (cd1.CustomerID == cd1_customerID)
            {
                lblCheckCustomerID.Text = "Customer ID Already Exist. Please re-enter another Customer ID";
            }
            else
            {
                string cd1_lastName = tbxLastName.Text;
                string cd1_firstName = tbxFirstName.Text;
                string cd1_nationality = ddlNat.SelectedValue;
                int cd1_contactNo = Convert.ToInt32(tbxContactNo.Text);
                string cd1_address = tbxAddress.Text;
                string cd1_email = tbxEmail.Text;

                customersDetails newCust = new customersDetails(cd1_customerID, cd1_lastName, cd1_firstName, cd1_nationality, cd1_contactNo, cd1_address, cd1_email);
                if (DBmanager.insertCustomerDetails(newCust) == 1)
                {
                    Session["customerID"] = cd1_customerID;
                    string querystring = "roomNum=" + c2;
                    
                    Server.Transfer("addRoomReservation.aspx?" + querystring );
                }
                else
                {
                    lblStatus.Text = "New Customer Details is added UNSUCCESSFULLY!";
                }
            }

            // go to add roomreservation
        }
    }
}